﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace RBAC.SQLServerDAL
{
    internal class Access : IDAL.IAccess
    {
        #region IBasicOperation<Access> Members

        public int GetRecordCount(string strWhere)
        {
            throw new NotImplementedException();
        }

        public int Add(RBAC.Model.Access model)
        {
            throw new NotImplementedException();
        }

        public bool Update(RBAC.Model.Access model)
        {
            throw new NotImplementedException();
        }

        public bool Update(string strWhere, params System.Data.SqlClient.SqlParameter[] commandParameters)
        {
            throw new NotImplementedException();
        }

        public bool Delete(int id)
        {
            throw new NotImplementedException();
        }

        public bool Delete(IList<int> id)
        {
            throw new NotImplementedException();
        }

        public bool Exists(int id)
        {
            throw new NotImplementedException();
        }

        public bool Exists(string id)
        {
            throw new NotImplementedException();
        }

        public RBAC.Model.Access GetModel(int id)
        {
            throw new NotImplementedException();
        }

        public IList<RBAC.Model.Access> GetIList(string strWhere, string Orderby)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet GetList(string strWhere, string Orderby)
        {
            //初始化新的DataSet对象,将使用表和关系填充对象
            DataSet dataSet = new DataSet();
            //以SQL数据表为依据来创建Bugs表及其列
            DataTable tblBugs = new DataTable("Bugs");
            DataColumn newColumn;
            newColumn = tblBugs.Columns.Add("BugID", Type.GetType("System.Int32"));
            newColumn.AutoIncrement = true;//自动增加
            newColumn.AutoIncrementSeed = 1;//起始为1
            newColumn.AutoIncrementStep = 1;//步长为1
            newColumn.AllowDBNull = false;//不允许为空
            //设置一个命名的约束
            UniqueConstraint constraint = new UniqueConstraint("Unique_BugID", newColumn);
            tblBugs.Constraints.Add(constraint);
            //为主键创建一个列数组
            DataColumn[] columnArray = new DataColumn[1];
            columnArray[0] = newColumn;
            //为PrimaryKey属性添加该数组
            tblBugs.PrimaryKey = columnArray;
            //Product的列
            newColumn = tblBugs.Columns.Add("Product", Type.GetType("System.Int32"));
            newColumn.AllowDBNull = false;
            newColumn.DefaultValue = 1;
            DataColumn bugProductColumn = newColumn;
            //Version 列
            newColumn = tblBugs.Columns.Add("Version", Type.GetType("System.String"));
            newColumn.AllowDBNull = false;
            newColumn.MaxLength = 50;
            newColumn.DefaultValue = "0.1";
            //Description列
            newColumn = tblBugs.Columns.Add("Description", Type.GetType("System.String"));
            newColumn.AllowDBNull = false;
            newColumn.MaxLength = 8000;
            newColumn.DefaultValue = "";
            //Reporter列
            newColumn = tblBugs.Columns.Add("Reporter", Type.GetType("System.Int32"));
            newColumn.AllowDBNull = false;
            DataColumn bugReporterColumn = newColumn;
            //基于所有创建的数据库架构添加行
            DataRow newRow;//声明一个新行
            newRow = tblBugs.NewRow();
            newRow["Product"] = 1;
            newRow["Version"] = "0.1";
            newRow["Description"] = "Crashes on load";
            newRow["Reporter"] = 5;
            tblBugs.Rows.Add(newRow);
            newRow = tblBugs.NewRow();
            newRow["Product"] = 1;
            newRow["Version"] = "0.1";
            newRow["Description"] = "Does not report correct owner of bug";
            newRow["Reporter"] = 5;
            tblBugs.Rows.Add(newRow);

            newRow = tblBugs.NewRow();
            newRow["Product"] = 1;
            newRow["Version"] = "0.1";
            newRow["Description"] = "Fails to reload properly";
            newRow["Reporter"] = 6;
            tblBugs.Rows.Add(newRow);

            newRow = tblBugs.NewRow();
            newRow["Product"] = 1;
            newRow["Version"] = "0.1";
            newRow["Description"] = "Does not show history of previous action";
            newRow["Reporter"] = 5;
            tblBugs.Rows.Add(newRow);

            newRow = tblBugs.NewRow();
            newRow["Product"] = 2;
            newRow["Version"] = "0.1";
            newRow["Description"] = "Loses data overnight";
            newRow["Reporter"] = 5;
            tblBugs.Rows.Add(newRow);

            newRow = tblBugs.NewRow();
            newRow["Product"] = 2;
            newRow["Version"] = "0.1";
            newRow["Description"] = "HTML is not shown properly";
            newRow["Reporter"] = 6;
            tblBugs.Rows.Add(newRow);

            //将表添加到DataSet中
            dataSet.Tables.Add(tblBugs);           
            return dataSet;

        }

        public System.Data.DataSet GetList(int PageSize, int PageIndex, string strWhere, string OrderFiled, string OrderBy)
        {
            throw new NotImplementedException();
        }

        public IList<RBAC.Model.Access> GetIList(int PageSize, int PageIndex, string strWhere, string OrderFiled, string OrderBy)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet GetList(string fldName, string tblName, string Condition, string orderBy, int pageSize, int currentIndex, ref int count)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
